from langchain_openai import ChatOpenAI
from pydantic import SecretStr
from langchain_core.prompts import PromptTemplate
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.prompts import ChatMessagePromptTemplate
from langchain_core.tools import tool
from pydantic import BaseModel, Field

# 创建模型实例（远程调用）
llm = ChatOpenAI(
    model_name="qwen3-max",
    temperature=0,
    openai_api_key=SecretStr("sk-f4fb03bbc29b4f0995b60dec52645af0"),
    openai_api_base="https://dashscope.aliyuncs.com/compatible-mode/v1",
    streaming=True,
)

# 创建提示词模板
prompt_template = PromptTemplate.from_template("今天的{something}真不错！")

# -------------------------------------------------------------------------------
# 创建聊天消息提示词模板
system_message_template = ChatMessagePromptTemplate.from_template(
    template="你是一位{role}专家、擅长回答{domain}领域的问题。",
    role="system"
)
# 创建用户消息提示词模板
user_message_template = ChatMessagePromptTemplate.from_template(
    template="用户问题：{question}。",
    role="user"
)
# 组合成聊天提示词模板
chat_prompt_template = ChatPromptTemplate.from_messages([
    system_message_template,
    user_message_template
])

# -------------------------------------------------------------------------------
# 定义一个简单的加法工具并使用装饰器表明函数功能
class AddInputArgs(BaseModel):
    a: int = Field(description="The first number to add.")
    b: int = Field(description="The second number to add.")

@tool(
    description="Add two numbers together.",
    args_schema=AddInputArgs,
    return_direct=False,  # 如果是True，直接返回结果而不是ToolCall对象，也没办法格式化自定义结果
)
def add(a, b):
    return a + b

def create_calc_tools():
    return [add]

calc_tools = create_calc_tools()